#pragma once

#include <vector>

namespace jianzhi_031
{

class Solution
{
public:
    bool validateStackSequences(const std::vector<int>& pushed,
                                const std::vector<int>& popped)
    {
        if (pushed.size() != popped.size())
            return false;
        std::vector<int> stack;
        for (int i = 0, j = 0; i < (int)pushed.size(); ++i) {
            stack.push_back(pushed.at(i));
            while (!stack.empty() && stack.back() == popped.at(j)) {
                stack.pop_back();
                ++j;
            }
        }
        return stack.empty();
    }
};

}  /* namespace jianzhi_031 */
